package com.hspedu.jichu.encapsulation;

public class Account {
    //姓名 余额 密码
    private String name;
    private double balance;
    private String password;

    public Account() {
    }

    public Account(String name, double balance, String password) {
        setName(name);
        setBalance(balance);
        setPassword(password);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        if (name.length()>1 && name.length()<5){
            this.name = name;
        }else{
            System.out.println("姓名长度必须是2-4位，默认为空");
            this.name = " ";
        }
    }

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        if (balance>20){
            this.balance = balance;
        }else{
            System.out.println("余额不能小于20");
            this.balance = 50;
        }
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        if (password.length()==6){
            this.password = password;
        }else{
            System.out.println("密码必须是6位，默认为000000");
            this.password = "000000";
        }
    }

    public String toString(){
        return "姓名="+name+" 余额="+balance+" 密码="+password;
    }
}
